import { forEach } from "../util"

export default class Module{
  constructor(node) {
    this._rwaModule = node
    this._children = {}
    this.state = node.state
  }
  get namespaced() {
    return this._rwaModule.namespace
  }
  getChild(key) {
    return this._children[key]
  }
  addChild(key, node) {
    this._children[key] = node
  }
  forEachMutation(fn) {
    if(this._rwaModule.mutations) {
      forEach(this._rwaModule.mutations, fn)
    }
  }
  forEachAction(fn) {
    if(this._rwaModule.actions) {
      forEach(this._rwaModule.actions, fn)
    }
  }
  forEachGetters(fn) {
    if(this._rwaModule.getters) {
      forEach(this._rwaModule.getters, fn)
    }
  }
  forEachChild(fn) {
    forEach(this._children, fn)
  }
}